package com.cx.bank.factory;

import com.cx.bank.dao.BankDaoInterface;

import java.io.FileInputStream;
import java.lang.reflect.Constructor;
import java.util.Properties;

public class UserDaoFactory {
    private BankDaoInterface userDao;
    private static UserDaoFactory instance;
    public UserDaoFactory() throws Exception{
        Properties properties = new Properties();
        FileInputStream fis = new FileInputStream("classInfo.properties");
        properties.load(fis);
        fis.close();
        String className = properties.getProperty("className");
        System.out.println(className);
        Class c = Class.forName(className);
        Constructor declaredConstructor = c.getDeclaredConstructor();
        declaredConstructor.setAccessible(true);
        Object o = declaredConstructor.newInstance();
        userDao = (BankDaoInterface) o;

    }
    public static UserDaoFactory getInstance() throws Exception{
        if (instance == null){
            instance = new UserDaoFactory();
        }
        return instance;
    }
    public BankDaoInterface createUserDao(){
        return this.userDao;
    }
}
